// pub struct Solution {}
use crate::solution::Solution;

impl Solution {
    pub fn minimum_abs_difference(mut arr: Vec<i32>) -> Vec<Vec<i32>> {
        let len = arr.len();
        let mut ret = Vec::new();
        let mut dv = vec![0; len-1];
        arr.sort();
        for i in 1..len {
            dv[i-1] = arr[i] - arr[i-1];
        }
        let min = dv.iter().min().unwrap();
        let mut i = 0;
        for d in &dv {
            if d == min {
                ret.push(vec![arr[i], arr[i+1]]);
            }
            i += 1;
        }
        ret
    }
}

#[cfg(test)]
mod tests {
    // 引用其他目录的impl Solution的话：use crate::algorithm::Solution;
    use super::*;

    #[test]
    fn test_1() {
        let mut arr = vec![4, 2, 3, 1];
        println!("{:?}", Solution::minimum_abs_difference(arr));
        arr = vec![4, 2, 3, 1];
        assert_eq!(Solution::minimum_abs_difference(arr), [[1,2],[2,3],[3,4]]);
    }
}

// 不在main.rs里就不用写了!
// fn main() {}